extends AnimatedSprite2D

var is_dashing := false

@onready var player_state:StateComponent = get_parent().get_node("PlayerState")


#region 动画系统
func update_animation_state():
	var direction = Input.get_axis("move_left", "move_right")
	# 状态优先级处理
	if player_state.get_current_state() == PlayerEnums.AnimState.HURT:
		handle_special_states_animation(direction)
		return
	
	# 常规状态处理
	if direction != 0:
		play("run")
		speed_scale = 1.2 if is_dashing else 1.0
	else:
		play("idle")
	
	# 统一方向处理
	update_character_direction(direction)

func update_character_direction(direction: float):
	if direction != 0:
		flip_h = direction < 0

func handle_special_states_animation(direction: float):
	if player_state.get_current_state() == PlayerEnums.AnimState.HURT:
		play("hurt")

	if direction != 0:
		flip_h = direction < 0
